﻿using System;
using System.Collections.Generic;
using System.IO;
using ProjScan.Config;
using ProjScan.RecordManager;
using ProjScan.RecordManager.AssetData;
using ProjScan.Tools;
using UnityEngine;

namespace ProjScan.ScanRule
{
	// Token: 0x020001A4 RID: 420
	internal abstract class RecordRule : BaseRule
	{
		// Token: 0x06000E2F RID: 3631
		public abstract void Check(AssetDataBase assetData);

		// Token: 0x06000E30 RID: 3632 RVA: 0x00002A20 File Offset: 0x00000C20
		public virtual void CheckDirSetted()
		{
		}

		// Token: 0x06000E31 RID: 3633 RVA: 0x000403A4 File Offset: 0x0003E5A4
		public override bool CheckSupportability(out string msg)
		{
			msg = "";
			return true;
		}

		// Token: 0x06000E32 RID: 3634 RVA: 0x000405A0 File Offset: 0x0003E7A0
		public bool DirTest(string relativeAssetPath)
		{
			bool flag = !this.SeparateDirSettingsEnabled;
			bool result;
			if (flag)
			{
				result = AssetPathManager.Instance.DirTest(relativeAssetPath);
			}
			else
			{
				bool result2 = false;
				ScanAssetsConfig[] array = this.target_configs;
				int num = 0;
				string text;
				for (;;)
				{
					bool flag2 = num >= array.Length;
					if (flag2)
					{
						break;
					}
					ScanAssetsConfig scanAssetsConfig = array[num];
					bool flag3 = scanAssetsConfig.matchingType == MatchingType.directory;
					if (flag3)
					{
						text = ToolsHelper.ConvertRelativePathToAbsolute(scanAssetsConfig.assetPath);
						bool flag4 = !Directory.Exists(text);
						if (flag4)
						{
							goto Block_4;
						}
						try
						{
							bool flag5 = (File.GetAttributes(text) & FileAttributes.Directory) == FileAttributes.Directory;
							if (flag5)
							{
								bool flag6 = ToolsHelper.IsDirContain(scanAssetsConfig.assetPath, relativeAssetPath);
								if (flag6)
								{
								}
							}
							else
							{
								bool flag7 = scanAssetsConfig.assetPath == relativeAssetPath;
								if (flag7)
								{
								}
							}
						}
						catch (Exception ex)
						{
							Debug.LogError("RecordRule::Dirtest: " + scanAssetsConfig.assetPath + " match " + relativeAssetPath);
						}
					}
					else
					{
						bool flag8 = ToolsHelper.IsMatch(scanAssetsConfig.assetPath, relativeAssetPath);
						if (flag8)
						{
						}
					}
					result2 = true;
					num++;
				}
				foreach (ScanAssetsConfig scanAssetsConfig2 in this.ignore_configs)
				{
					bool flag9 = scanAssetsConfig2.matchingType == MatchingType.directory;
					if (flag9)
					{
						bool flag10 = ToolsHelper.IsDirContain(scanAssetsConfig2.assetPath, relativeAssetPath);
						if (flag10)
						{
							result2 = false;
						}
					}
					else
					{
						bool flag11 = ToolsHelper.IsMatch(scanAssetsConfig2.assetPath, relativeAssetPath);
						if (flag11)
						{
							result2 = false;
						}
					}
				}
				return result2;
				Block_4:
				Debug.Log("RecordRule::DirTest - Path " + text + " not exists!");
				result = false;
			}
			return result;
		}

		// Token: 0x06000E33 RID: 3635 RVA: 0x00040768 File Offset: 0x0003E968
		public override void DumpToRuleCSV(ref StreamWriter sw)
		{
			string[] values = new string[]
			{
				base.GetType().FullName.Replace("ProjScan.ScanRule.", ""),
				",",
				this.SceneId.ToString(),
				",,",
				this.TableTag,
				",",
				this.dataID.ToString()
			};
			string value = string.Concat(values);
			sw.WriteLine(value);
		}

		// Token: 0x06000E34 RID: 3636 RVA: 0x000407F0 File Offset: 0x0003E9F0
		public override void DumpToThresCSV(ref StreamWriter sw)
		{
			bool separateDirSettingsEnabled = this.SeparateDirSettingsEnabled;
			if (separateDirSettingsEnabled)
			{
				foreach (ScanAssetsConfig scanAssetsConfig in this.target_configs)
				{
					string value = base.GetType().FullName.Replace("ProjScan.ScanRule.", "") + "," + scanAssetsConfig.ToString();
					sw.WriteLine(value);
				}
			}
		}

		// Token: 0x06000E35 RID: 3637 RVA: 0x00040868 File Offset: 0x0003EA68
		public override void FixRule()
		{
			bool flag = this.failAssetInfos != null && this.failAssetInfos.Count != 0;
			if (flag)
			{
				Dictionary<string, FailedAssetInfo> dictionary = new Dictionary<string, FailedAssetInfo>(this.failAssetInfos.Count);
				int num = 0;
				foreach (KeyValuePair<string, FailedAssetInfo> keyValuePair in this.failAssetInfos)
				{
					bool flag2 = !keyValuePair.Value.ShouldBeFixed || keyValuePair.Value.IsFixed;
					if (!flag2)
					{
						ToolsHelper.ShowProgressBar("Fixing....", "Fixing Resource at:  (" + keyValuePair.Key + ")", 1f / (float)num, false);
						FailedAssetInfo failedAssetInfo = new FailedAssetInfo();
						try
						{
							bool flag3 = this.InvokeFixer(keyValuePair.Key);
							if (flag3)
							{
								keyValuePair.Value.ShouldBeFixed = false;
								keyValuePair.Value.IsFixed = true;
								FixLog.Instance.Log(this.fixerType, keyValuePair.Key);
							}
							failedAssetInfo.ShouldBeFixed = keyValuePair.Value.ShouldBeFixed;
							failedAssetInfo.IsFixed = keyValuePair.Value.IsFixed;
							failedAssetInfo.ShouldJoinWhiteList = keyValuePair.Value.ShouldJoinWhiteList;
							dictionary.Add(keyValuePair.Key, failedAssetInfo);
						}
						catch (Exception ex)
						{
							ScanLog.UnityLogError("Fixer Error: " + ex.ToString());
						}
						num++;
					}
				}
				foreach (KeyValuePair<string, FailedAssetInfo> keyValuePair2 in dictionary)
				{
					bool flag4 = this.failAssetInfos.ContainsKey(keyValuePair2.Key);
					if (flag4)
					{
						this.failAssetInfos[keyValuePair2.Key] = keyValuePair2.Value;
					}
				}
			}
		}

		// Token: 0x06000E36 RID: 3638 RVA: 0x00040AA4 File Offset: 0x0003ECA4
		protected virtual string GetFailedColumn()
		{
			return null;
		}

		// Token: 0x06000E37 RID: 3639
		public abstract IRecordManager GetManager();

		// Token: 0x06000E38 RID: 3640 RVA: 0x00009C40 File Offset: 0x00007E40
		public virtual bool HasFailedInfos()
		{
			return false;
		}

		// Token: 0x06000E39 RID: 3641 RVA: 0x00040AB8 File Offset: 0x0003ECB8
		public override void Init()
		{
			bool flag = this.FailedInfos == null;
			if (flag)
			{
				this.FailedInfos = new List<string>();
			}
			else
			{
				this.FailedInfos.Clear();
			}
			bool flag2 = this.FailedRecords == null;
			if (flag2)
			{
				this.FailedRecords = new List<int>();
			}
			else
			{
				this.FailedRecords.Clear();
			}
		}

		// Token: 0x06000E3A RID: 3642 RVA: 0x0000715B File Offset: 0x0000535B
		public void SetDirConfigs(bool _SeparateDirSettingsEnabled, ScanAssetsConfig[] target_configs, ScanAssetsConfig[] ignore_configs)
		{
			this.SeparateDirSettingsEnabled = _SeparateDirSettingsEnabled;
			this.target_configs = target_configs;
			this.ignore_configs = ignore_configs;
			this.CheckDirSetted();
		}

		// Token: 0x06000E3B RID: 3643 RVA: 0x0000717A File Offset: 0x0000537A
		public void SetWhiteList(List<string> inputList)
		{
			this.whiteList = inputList;
		}

		// Token: 0x06000E3C RID: 3644 RVA: 0x0000A3A0 File Offset: 0x000085A0
		public bool ThresholdTest(string assetPath)
		{
			return true;
		}

		// Token: 0x06000E3D RID: 3645 RVA: 0x00040B1C File Offset: 0x0003ED1C
		public bool WhiteListTest(string assetPath)
		{
			bool flag = this.whiteList != null && this.whiteList.Count != 0;
			if (flag)
			{
				foreach (string a in this.whiteList)
				{
					bool flag2 = a == assetPath;
					if (flag2)
					{
						return true;
					}
				}
			}
			return false;
		}

		// Token: 0x040008D3 RID: 2259
		public bool hasSeparateTargetDirSettings;

		// Token: 0x040008D4 RID: 2260
		protected ScanAssetsConfig[] target_configs;

		// Token: 0x040008D5 RID: 2261
		protected ScanAssetsConfig[] ignore_configs;

		// Token: 0x040008D6 RID: 2262
		public bool SeparateDirSettingsEnabled;

		// Token: 0x040008D7 RID: 2263
		private List<string> whiteList;

		// Token: 0x040008D8 RID: 2264
		public List<int> FailedRecords;

		// Token: 0x040008D9 RID: 2265
		public List<string> FailedInfos;
	}
}
